package com.example.designer.observer.v2;

import org.springframework.util.ObjectUtils;

import java.nio.channels.Pipe;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhaoyunlong
 * @date 2020/12/24
 * @description
 */
public class WakeUpEvent<T>{

    T source;

    public WakeUpEvent(T source) {
        this.source = source;
    }

    List<WakeUpEventListener> wakeUpEventListeners = new ArrayList<>();

    public WakeUpEvent addWakeUpListener(WakeUpEventListener wakeUpEventListener){

        if (wakeUpEventListener == null) {
            throw new RuntimeException("添加wakeUp listener  为 空");
        }
        wakeUpEventListeners.add(wakeUpEventListener);
        return this;
    }

    public void doWakeUp(WakeUpEvent<T> wakeUpEvent) {
        wakeUpEventListeners.forEach(wakeUpEventListener -> {
            wakeUpEventListener.doWakeUp(wakeUpEvent);
        });
    }

    public T getSource() {
        return source;
    }
}
